package com.zhiyou100.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhiyou100.model.Stu;
import com.zhiyou100.service.StuService;
import com.zhiyou100.service.TeaService;

@Controller
@RequestMapping("stu")
public class StuController {
	@Resource
	StuService stuService;
	@Resource
	TeaService teaService;

	@RequestMapping("show.do")
	public String show(Model model) {
		model.addAttribute("stus", stuService.queryAll());
		return "stu/show";
	}

	@RequestMapping("add.do")
	public String add(Model model) {
		model.addAttribute("teas", teaService.queryAll());

		return "stu/add";
	}

	@RequestMapping("insert.do")
	public String insert(Model model, Stu stu) {
		stuService.add(stu);

		return "redirect:show.do";
	}

	@RequestMapping("edit.do")
	public String edit(Integer id, Model model) {
		model.addAttribute("stu", stuService.findById(id));
		model.addAttribute("teas", teaService.queryAll());
		return "stu/update";
	}

	@RequestMapping("delete.do")
	public String delete(Integer id) {

		stuService.deleteById(id);

		return "redirect:show.do";
	}

	@RequestMapping("update.do")
	public String update(Stu stu) {
		System.out.println(stu);
		stuService.update(stu);
		return "redirect:show.do";
	}
}
